﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamSystem.Mdeol;
using ExamSystem.BLL;
namespace ExamSystem.ht
{
    public partial class TQuestion_List : System.Web.UI.Page
    {
        private TquestionBLL tb = new TquestionBLL();
        private TkechengBLL tkb = new TkechengBLL();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                try
                {
                    string tqid = this.Request.QueryString["id"];
                    if (!string.IsNullOrEmpty(tqid))
                    {
                        int b = tb.delete(int.Parse(tqid));

                        if (b > 0)
                        {
                            util.FunHelper.LayerAlter(this, "删除成功", "TQuestion_List.aspx");
                        }

                    }
                }
                catch
                {
                    util.FunHelper.LayerAlter(this, "删除失败");
                }
               


                List<Tkecheng> list = tkb.selectkckecheng();

                Tkecheng bi = new Tkecheng(0, "全部");
                list.Insert(0, bi);

                this.tkcId.DataSource = list;
                this.tkcId.DataTextField = "tkcname";
                this.tkcId.DataValueField = "tkcid";
                this.tkcId.DataBind();

                this.mohu();
            }
        }
        private void mohu()
        {
            string name = this.tqName.Value;
            int tkcid = int.Parse(this.tkcId.Value);
            List<Tquestion> list = tb.mohuquert(tkcid, name);
            this.lbTotal.InnerText = list.Count+"";
            //分页类
            PagedDataSource page = new PagedDataSource();
            //属性
            page.AllowPaging = true;
            page.PageSize = 5;
            page.CurrentPageIndex = int.Parse(this.pageNo.Value) - 1;
            page.DataSource = list;


            //绑定数据源
            this.Repeater1.DataSource = page;
            //绑定数据
            this.Repeater1.DataBind();


            //当前几页总共几页
            this.lbPageCount.InnerText = this.pageNo.Value;
            this.lbPageNo.InnerText = page.PageCount + "";

            //规避按钮
            if (page.IsFirstPage)
            {
                this.btnFirst.Enabled = false;
                this.btnUp.Enabled = false;
            }
            else
            {
                this.btnFirst.Enabled = true; ;
                this.btnUp.Enabled = true; ;
            }


            if (page.IsLastPage)
            {
                this.btnLast.Enabled = false;
                this.btnDown.Enabled = false;
            }
            else
            {
                this.btnLast.Enabled = true; ;
                this.btnDown.Enabled = true; ;
            }
        }
    
        //查询
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.mohu();
        }
        //第一页
        protected void btnFirst_Click(object sender, EventArgs e)
        {
            this.pageNo.Value = "1";
            this.mohu();
        }
        //上一页
        protected void btnUp_Click(object sender, EventArgs e)
        {
            int pageno = int.Parse(this.pageNo.Value);
            pageno--;
            this.pageNo.Value = pageno + "";
            this.mohu();
        }
        //下一页
        protected void btnDown_Click(object sender, EventArgs e)
        {
            int pageno = int.Parse(this.pageNo.Value);
            pageno++;
            this.pageNo.Value = pageno + "";
            this.mohu();
        }
        //尾页
        protected void btnLast_Click(object sender, EventArgs e)
        {
            this.pageNo.Value = this.lbPageNo.InnerText;
            this.mohu();
        }
    }
}